package org.zhangsh.netty.handler;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;

/**
 * </p>
 *
 * @author zhangshuhui
 * @version 1.0.0
 * @since 2019/8/21
 */
public class NewDelimiterDecoder extends DelimiterBasedFrameDecoder {

    public NewDelimiterDecoder(int maxFrameLength, ByteBuf delimiter) {
        super(maxFrameLength, delimiter);
    }

    @Override
    protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {

        if(buffer.isReadable()){
            byte[] copys = new byte[buffer.readableBytes()];
            buffer.getBytes(buffer.readerIndex(), copys);


            System.out.println("NewDelimiterDecoder... " + copys.length + "   :" + new String(copys));
            return super.decode(ctx, buffer);
        }

        return super.decode(ctx, buffer);

    }


}
